home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.internetmci.com!panix!usenet
- From: gugu@panix.com (Dae Choi)
- Newsgroups: comp.lang.c++
- Subject: Re: COOL: Something you can do in "C" you can NOT do in "C++"
- Date: 8 Mar 1996 19:58:27 GMT
- Organization: PANIX Public Access Internet and Unix, NYC
- Message-ID: <1094.6641T918T238@panix.com>
- References: <4hpov3$krb@qualcomm.com>
- NNTP-Posting-Host: gugu.dialup.access.net
- X-Newsreader: THOR 2.22 (Amiga;TCP/IP) *UNREGISTERED*
-
-
- >Hi,
-
- >I am teaching myself C++, but my interest in the language just dropped.
- >I want to read cin as a binary file and output cout the same as well. I read
- >the FAQs on C++ and guess what YOU CAN'T DO IT.
-
- >Come on, THERE HAS TO BE A WORK AROUND! OS/2 using EMX if it matters, but
- >hopefully something fairly portable.
-
- Try this,
-
- #include <fstream.h>
-
- int main(void)
- {
- int count;
-
- float price;
-
- // Opens output file stream "STOCK.DAT" as binary file
- ofstream stocks("STOCKS.DAT",ios::binary);
-
- if (stocks.fail()) //checking if file didn't fail
- cerr <<"Error opening file Stock.dat"<<endl;
- else {
- for (count =1;count<=30;count++)
- {
- price=count*100.0;
- //output to the file
- stocks.write((char *)&price,sizeof(float));
- }
- stocks.close();
- //closes the file
- } //end if
- } //end program
-
- --------------------------------------------------------------------
-
- I hope this helps...
-
-
-
- gugu@panix.com
-
-